import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
// 获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
// 修改原型对象中的push方法，replace方法就把VueRouter.prototype.push的push换成replace即可
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    redirect: '/homemain'
  },
  {
    path: '/login',
    component: () => import('@/views/login')
  },
  {
    path: '/layout',
    component: () => import('@/layout'),
    children: [
      {
        path: '/home',
        component: () => import('@/views/second/home'),
        children: [
          {
            path: '/homemain',
            component: () => import('@/views/second/homeMain')
          },
          {
            path: '/business',
            component: () => import('@/views/second/business')
          },
          {
            path: '/operation',
            component: () => import('@/views/second/operation')
          }
        ]
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
